
function drawcharts(data){

	$('#camenbertProbl').highcharts({
		chart: {
			plotBackgroundColor: null,
			plotBorderWidth: null,
			plotShadow: false
		},
		title: {
			text: 'Catégorie des appels'
		},
		tooltip: {
			pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
		},
		plotOptions: {
			pie: {
				allowPointSelect: true,
				cursor: 'pointer',
				dataLabels: {
					enabled: true,
					format: '<b>{point.name}</b>: {point.percentage:.1f} %',
					style: {
						color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
					}
				}
			}
		},

		series: [{
			type: 'pie',
			name: 'Nombre d\'appel lié ',
			data: data
		}]
	});
}


function getpercent(data,total){
	return data/total*100;
}
function drawpie(){
	$.ajax({url:"retourAjax/dataProbl.php"
	}).done(function(data){
		data=JSON.parse(data);
		vretour=[];
		total=0;
		for(i=0; i<data.length;i++){
			total=total+parseInt(data[i].num);
		}
		for(i=0; i<data.length;i++){
			percent=getpercent(data[i].num, total);
			vretour.push([utf8_decode(data[i].nature), percent]);
		}
		drawcharts(vretour);
		
	});
}
function selectRadio(){
	var choix = document.getElementById("date");
	var choix2 = document.getElementById("date2");
	if(choix.checked){
		TB = document.getElementById("dateDebut");
		TB2 = document.getElementById("dateFin");
		OK = document.getElementById("OK");
		TB.style.display = "none";
		TB2.style.display = "none";
		OK.style.display = "none";

		//Création du graph
		drawpie();
	}
	else{	
		TB = document.getElementById("dateDebut");
		TB2 = document.getElementById("dateFin");
		OK = document.getElementById("OK");
		TB.style.display = "block";
		TB2.style.display = "block";
		OK.style.display = "block";
		return true;

	}
}

function afficheGraph(){
	var choix = document.getElementById("dateDebut").value;
	var choix2 = document.getElementById("dateFin").value;	
//	dateDebut = choix.split("/");
//	DebutModif = dateDebut[2]+"-"+dateDebut[0]+"-"+dateDebut[1];
//	dateFin = choix2.split("/");
//	FinModif = dateFin[2]+"-"+dateFin[0]+"-"+dateFin[1];
	//Création du graph
	data= {"DateDebut": choix,"DateFin": choix2};
	$.ajax({url:"retourAjax/dataProbl.php",
		type: "POST",
		data: data
	}).done(function(data){
		
		data=JSON.parse(data);
		vretour=[];
		total=0;
		for(i=0; i<data.length;i++){
			total=total+parseInt(data[i].num);
		}
		for(i=0; i<data.length;i++){
			percent=getpercent(data[i].num, total);
			vretour.push([data[i].nature, percent]);
		}
		drawcharts(vretour);
	});
}








